$(document)
        .ready(
                function() {
                	
                    $('#calendar')
                            .fullCalendar(
                                    {
                                        header : {
                                            right : 'prev,next today',
                                            center : 'title',
                                            left : 'month,agendaWeek,agendaDay'
                                        },
                                        buttonIcons : {
                                            prev : 'circle-triangle-w',
                                            next : 'circle-triangle-e'
                                        },
                                        monthNames : ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
                                        monthNamesShort : ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
                                        dayNames : ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
                                        dayNamesShort : ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
                                        today : ["今天"],
                                        firstDay : 1,
                                        buttonText : {
                                            today : '本日',
                                            month : '月',
                                            week : '周',
                                            day : '日',
                                            prev : '上一月',
                                            next : '下一月'
                                        },
                                        weekends : true,
                                        allDaySlot : false,
                                        selectable : true,
                                        selectHelper : true,
                                        aspectRatio : 1,
                                        editable : false,
                                        allDayDefault : false,
                                        minTime : 8,
                                        maxTime : 18,
                                        defaultEventMinutes : 120,// 默认执行两个小时
                                        viewDisplay : function(view) {// 动态把数据查出，按照月份动态查询
                                            var viewStart = $.fullCalendar.formatDate(view.start, "yyyy-MM-dd HH:mm:ss");
                                            var viewEnd = $.fullCalendar.formatDate(view.end, "yyyy-MM-dd HH:mm:ss");
                                            $("#calendar").fullCalendar('removeEvents');
                                            if ($("#roomname").size()==0||$("#roomname").html() == "meeting room") {
                                                $.get("/meetings/books/my", {
                                                    start : viewStart,
                                                    end : viewEnd
                                                }, function(data) {
                                                    var events = [];
                                                    for ( var i = 0; i < data.length; i++) {
                                                        var ev = data[i];
                                                        events.push({
                                                            title : ev.meetingTitle,
                                                            start : new Date(ev.bookStartTime),
                                                            end : new Date(ev.bookEndTime),
                                                            id : ev.id,
                                                            fullname : ev.workerId,
                                                            confname : ev.meetingName,
                                                            confshortname : ev.meetingName,
                                                            description : ev.meetingDescription,
                                                            topic : ev.meetingTitle
                                                        });
                                                        for ( var i = 0; i < events.length; i++) {
                                                            $("#calendar").fullCalendar('renderEvent', events[i], true);
                                                        }
                                                    }
                                                    
                                                }); // 把从后台取出的数据进行封装以后在页面上以fullCalendar的方式进行显示
                                            }
                                            else {
                                                $.get("/meetings/books/" + $("#meetingroom").val(), {
                                                    start : viewStart,
                                                    end : viewEnd
                                                }, function(data) {
                                                    var events = [];
                                                    for ( var i = 0; i < data.length; i++) {
                                                        var ev = data[i];
                                                        events.push({
                                                            title : ev.meetingTitle,
                                                            start : new Date(ev.bookStartTime),
                                                            end : new Date(ev.bookEndTime),
                                                            id : ev.id,
                                                            fullname : ev.workerId,
                                                            confname : ev.meetingName,
                                                            confshortname : ev.meetingName,
                                                            description : ev.meetingDescription,
                                                            topic : ev.meetingTitle
                                                        });
                                                        for ( var i = 0; i < events.length; i++) {
                                                            $("#calendar").fullCalendar('renderEvent', events[i], true);
                                                        }
                                                    }
                                                    
                                                }); // 把从后台取出的数据进行封装以后在页面上以fullCalendar的方式进行显示
                                            }
                                        },
                                        currentTimezone : 'Asia/Beijing',
                                        defaultView : 'month',
                                        theme : true,
                                        editable : true,
                                        allDaySlot : false,
                                        dayClick : function(date, allDay, jsEvent, view) {
                                            var selectdate = $.fullCalendar.formatDate(date, "yyyy-MM-dd");
                                            // $("#end").datetimepicker('setDate',
                                            // selectdate);// 给时间空间赋值
                                            if (compare2Date($.fullCalendar.formatDate(new Date(), "yyyy-MM-dd"), selectdate) == 0) {
                                                // Dialog message
                                                $("#dialog-message").dialog({
                                                    autoOpen : false,
                                                    modal : true,
                                                    buttons : {
                                                        确定 : function() {
                                                            $(this).dialog("close");
                                                        }
                                                    }
                                                });
                                                $("#dialog-message").dialog("open");
                                                return false;
                                            }
                                            $("#reservebox").dialog({
                                                autoOpen : false,
                                                height : 450,
                                                width : 400,
                                                title : '预约会议室于 ' + selectdate,
                                                modal : true,
                                                position : "center",
                                                draggable : false,
                                                beforeClose : function(event, ui) {
                                                    $.validationEngine.closePrompt("#meeting");
                                                    $.validationEngine.closePrompt("#start");
                                                    $.validationEngine.closePrompt("#end");
                                                },
                                                buttons : {
                                                    "关闭" : function() {
                                                        $(this).dialog("close");
                                                    },
                                                    "预约" : function() {
                                                        if ($("#reserveformID").validationEngine({
                                                            returnIsValid : true
                                                        })) {
                                                            var startdatestr = $("#start").val();
                                                            var enddatestr = $("#end").val();
                                                            var title = $("#title").val(); // 标题
                                                            var details = $("#details").val(); // 内容
                                                            var confid = $("#meeting").val();
                                                            var repweeks = $("#repweeks").val();
                                                            if (repweeks == null) {
                                                                repweeks = 0;
                                                            }
                                                            var startdate = $.fullCalendar.parseDate(selectdate + "T" + startdatestr);
                                                            var enddate = $.fullCalendar.parseDate(selectdate + "T" + enddatestr);
                                                            var event = new Object()
                                                            event.fullname = title;
                                                            event.confname = title;
                                                            event.start = startdate;
                                                            event.end = enddate;
                                                            event.description = details;
                                                            if (repweeks == 0) {
                                                                var schdata = {
                                                                    startdate : startdate.pattern("yyyy-MM-dd HH:mm:ss"),
                                                                    enddate : enddate.pattern("yyyy-MM-dd HH:mm:ss"),
                                                                    repweeks : repweeks,
                                                                    meetingId : confid,
                                                                    title : title,
                                                                    details : details
                                                                };
                                                                $.get("/meetings/book", schdata, function(data) {
                                                                    if (data == true) {
                                                                        //$("#calendar").fullCalendar('renderEvent', event,true);
                                                                        //$('#calendar').fullCalendar('updateEvent', event);
                                                                        alert("预定会议成功！");
                                                                        window.location.href=window.location.href;
                                                                    }
                                                                    else {
                                                                        alert("预定会议失败！");
                                                                    }
                                                                });
                                                            }
                                                            else {
                                                                var str = "";
                                                                $("input[name='weeks']:checked").each(function() {
                                                                    str += $(this).val() + ",";
                                                                })
                                                                var schdata = {
                                                                    startdate : startdate.pattern("yyyy-MM-dd HH:mm:ss"),
                                                                    enddate : enddate.pattern("yyyy-MM-dd HH:mm:ss"),
                                                                    repweeks : repweeks,
                                                                    meetingId : confid,
                                                                    title : title,
                                                                    details : details,
                                                                    weeks : str
                                                                };
                                                                $.get("/meetings/book/periodic", schdata, function(data) {
                                                                    var success=data[0];
                                                                    var failed=data[1];
                                                                    var html="";
                                                                    for(var i=0;i<failed.length;i++){
                                                                       var item=failed[i];
                                                                       var temp='<div class="ui-state-error ui-corner-all"><p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span><strong>预约失败:</strong> '+item+'</p></div>';
                                                                       html+=temp;
                                                                    }
                                                                    $("#dialog-book").html(html);
                                                                    $("#dialog-book").dialog({
                                                                        autoOpen : false,
                                                                        height : 450,
                                                                        width : 400,
                                                                        title : '批量预定会议室失败 ',
                                                                        modal : true,
                                                                        position : "center",
                                                                        draggable : false,
                                                                        beforeClose : function(event, ui) {
                                                                        },
                                                                        buttons : {
                                                                            "放弃预约" : function() {
                                                                                $(this).dialog("close");
                                                                            },
                                                                            "继续预约" : function() {
                                                                                $(this).dialog("close");
                                                                                $.get("/meetings/book/lot", schdata, function(data) {
                                                                                    if(data==true){
                                                                                        alert("周期预约成功!");
                                                                                        window.location.href=window.location.href;
                                                                                    }
                                                                                    else{
                                                                                        alert("周期预约失败!");
                                                                                    }
                                                                                });
                                                                            }
                                                                        }
                                                                    });
                                                                    if(failed.length==0&&success.length>0){
                                                                        $.get("/meetings/book/lot", schdata, function(result) {
                                                                            if(result==0){
                                                                                alert("周期预约成功!");
                                                                                window.location.href=window.location.href;
                                                                            }else if(result==-1){
                                                                                alert("权限不够！");
                                                                            }else if(result==-2){
                                                                                alert("数据错误！");
                                                                            }else{
                                                                            	  alert("其他错误！");
                                                                            }
                                                                            
                                                                        });
                                                                    }
                                                                    else{
                                                                        if(success.length>0){
                                                                        $("#dialog-book").dialog("open");
                                                                        return false;
                                                                        }
                                                                        else{
                                                                            alert("周期预约失败!");
                                                                        }
                                                                    }
                                                                    
                                                                });
                                                            }
                                                            $(this).dialog("close");
                                                        }
                                                    }
                                                }
                                            });
                                            $("#reservebox").dialog("open");
                                            return false;
                                        },
                                        weekMode : "variable",
                                        timeFormat : 'HH:mm{ - HH:mm}',
                                        eventClick : function(event) {
                                            var fstart = $.fullCalendar.formatDate(event.start, "yyyy/MM/dd HH:mm");
                                            var fend = $.fullCalendar.formatDate(event.end, "HH:mm");
                                            var schdata = {
                                                sid : event.sid,
                                                deleted : 1,
                                                uid : event.uid
                                            };
                                            
                                            $("#reserveinfo").dialog({
                                                autoOpen : false,
                                                height : 280,
                                                width : 400,
                                                modal : true,
                                                position : "center",
                                                draggable : false,
                                                buttons : {
                                                    "关闭" : function() {
                                                        $(this).dialog("close");
                                                    }
                                                }
                                            });
                                            
                                            if (1 == 1 || 2 == schdata.uid) {
                                                $("#reserveinfo").dialog("option", "buttons", {
                                                    "关闭" : function() {
                                                        $(this).dialog("close");
                                                    },
                                                    "删除" : function() {
                                                        var aa = window.confirm("警告：确定要删除记录，删除后无法恢复！");
                                                        if (aa) {
                                                            var para = {
                                                                id : event.id
                                                            };
                                                            
                                                            $.ajax({
                                                                type : "POST", // 使用post方法访问后台
                                                                url : "/meetings/delete/" + event.id, // 要访问的后台地址
                                                                data : para, // 要发送的数据
                                                                success : function(data) {
                                                                    // 对话框里面的数据提交完成，data为操作结果
                                                                    if (data == true) {
                                                                        $('#calendar').fullCalendar('removeEvents', event.id);
                                                                        alert("删除会议成功！");
                                                                    }
                                                                    else {
                                                                        window.alert("删除会议失败，请重新尝试！");
                                                                    }
                                                                }
                                                            
                                                            });
                                                            
                                                        }
                                                        $(this).dialog("close");
                                                    }
                                                
                                                });
                                            }
                                            
                                            var showtopic = '';
                                            
                                            if (event.topic.length > 15) {
                                                showtopic = event.topic.substring(0, 15) + '...';
                                            }
                                            else {
                                                showtopic = event.topic;
                                            }
                                            
                                            $("#revdesc")
                                                    .html(
                                                            '<div style="font-weight:bold;color:#5383c2;border-bottom: 1px dotted #5383c2; padding: 3px 0px 3px;">'
                                                                    + showtopic
                                                                    + "</div>"
                                                                    + '<div style="padding: 10px 0px 3px">'
                                                                    + event.confname
                                                                    + '</a><div style="background:#A4C3E3; text-align:center; padding:5px;color:#1d5987;font-weight:bold;font-size:9px"><span style="background:'
                                                                    + event.confcolor + ';width:14px;height:14px;color:#E3E3E3;font-size:10px;position:relative;left:0;top:0;">'
                                                                    + event.confshortname + '</span>&nbsp;' + event.confname + ' by ' + event.fullname
                                                                    + '</div></div><div style="float:right;width:220px; padding:0px ; margin:0px">' + event.description
                                                                    + '</div><div style="clear:both"></div></div>');
                                            
                                            $("#reserveinfo").dialog({
                                                title : fstart + "-" + fend + " " + showtopic
                                            });
                                            
                                            $("#reserveinfo").dialog("open");
                                            return false;
                                        },
                                        loading : function(bool) {
                                            if (bool)
                                                $('#loading').show();
                                            else
                                                $('#loading').hide();
                                        },
                                        eventMouseover : function(calEvent, jsEvent, view) {
                                            var fstart = $.fullCalendar.formatDate(calEvent.start, "yyyy/MM/dd HH:mm");
                                            var fend = $.fullCalendar.formatDate(calEvent.end, "HH:mm");
                                            $(this).attr('title', fstart + " - " + fend + " " + calEvent.topic + " : " + calEvent.description);
                                            $(this).css('font-weight', 'normal');
                                            $(this).tooltip({
                                                effect : 'toggle',
                                                cancelDefault : true
                                            });
                                        },
                                        eventMouseout : function(calEvent, jsEvent, view) {
                                            $(this).css('font-weight', 'normal');
                                        },
                                        eventRender : function(event, element) {
                                            var fstart = $.fullCalendar.formatDate(event.start, "HH:mm");
                                            var fend = $.fullCalendar.formatDate(event.end, "HH:mm");
                                            // Bug in IE8
                                            // element.html('<a href=#>' +
                                            // fstart + "-" + fend + '<div
                                            // style=color:#E5E5E5>' +
                                            // event.title + "</div></a>");
                                        },
                                        eventAfterRender : function(event, element, view) {
                                            var fstart = $.fullCalendar.formatDate(event.start, "HH:mm");
                                            var fend = $.fullCalendar.formatDate(event.end, "HH:mm");
                                            // element.html('<a
                                            // href=#><div>Time: ' + fstart +
                                            // "-" + fend + '</div><div>Room:' +
                                            // event.confname + '</div><div
                                            // style=color:#E5E5E5>Host:' +
                                            // event.fullname + "</div></a>");
                                            
                                            var confbg = '';
                                            if (event.confid == 1) {
                                                confbg = confbg + '<span class="fc-event-bg"></span>';
                                            }
                                            else if (event.confid == 2) {
                                                confbg = confbg + '<span class="fc-event-bg"></span>';
                                            }
                                            else if (event.confid == 3) {
                                                confbg = confbg + '<span class="fc-event-bg"></span>';
                                            }
                                            else if (event.confid == 4) {
                                                confbg = confbg + '<span class="fc-event-bg"></span>';
                                            }
                                            else if (event.confid == 5) {
                                                confbg = confbg + '<span class="fc-event-bg"></span>';
                                            }
                                            else if (event.confid == 6) {
                                                confbg = confbg + '<span class="fc-event-bg"></span>';
                                            }
                                            else {
                                                confbg = confbg + '<span class="fc-event-bg"></span>';
                                            }
                                            
                                            var titlebg = '<span class="fc-event-conf">' + event.confshortname + '</span>';
                                            
                                            if (event.repweeks > 0) {
                                                titlebg = titlebg + '<span class="fc-event-conf" style="background:#fff;top:0;right:40;color:#3974BC;font-weight:bold">R</span>';
                                            }
                                            
                                            if (view.name == "month") {// 按月份
                                                var evtcontent = '<div class="fc-event-vert"><a>';
                                                evtcontent = evtcontent + confbg;
                                                evtcontent = evtcontent + '<span class="fc-event-titlebg">' + fstart + " - " + fend + titlebg + '</span>';
                                                evtcontent = evtcontent + '<span>Room: ' + event.confname + '</span>';
                                                evtcontent = evtcontent + '<span>Host: ' + event.fullname + '</span>';
                                                evtcontent = evtcontent + '</a><div class="ui-resizable-handle ui-resizable-e"></div></div>';
                                                element.html(evtcontent);
                                            }
                                            else if (view.name == "agendaWeek") {// 按周
                                                var evtcontent = '<a>';
                                                evtcontent = evtcontent + confbg;
                                                evtcontent = evtcontent + '<span class="fc-event-time">' + fstart + "-" + fend + titlebg + '</span>';
                                                evtcontent = evtcontent + '<span>' + event.confname + ' by ' + event.fullname + '</span>';
                                                // evtcontent = evtcontent +
                                                // '<span>' + event.fullname +
                                                // '</span>';
                                                evtcontent = evtcontent
                                                        + '</a><span class="ui-icon ui-icon-arrowthick-2-n-s"><div class="ui-resizable-handle ui-resizable-s"></div></span>';
                                                element.html(evtcontent);
                                            }
                                            else if (view.name == "agendaDay") {// 按日
                                                var evtcontent = '<a>';
                                                evtcontent = evtcontent + confbg;
                                                evtcontent = evtcontent + '<span class="fc-event-time">' + fstart + " - " + fend + titlebg + '</span>';
                                                evtcontent = evtcontent + '<span>Room: ' + event.confname + '</span>';
                                                evtcontent = evtcontent + '<span>Host: ' + event.fullname + '</span>';
                                                evtcontent = evtcontent + '<span>Topic: ' + event.topic + '</span>';
                                                evtcontent = evtcontent
                                                        + '</a><span class="ui-icon ui-icon-arrow-2-n-s"><div class="ui-resizable-handle ui-resizable-s"></div></span>';
                                                element.html(evtcontent);
                                            }
                                        },
                                        eventDragStart : function(event, jsEvent, ui, view) {
                                            ui.helper.draggable("option", "revert", true);
                                        },
                                        eventDragStop : function(event, jsEvent, ui, view) {
                                        },
                                        eventDrop : function(event, dayDelta, minuteDelta, allDay, revertFunc, jsEvent, ui, view) {
                                            
                                            if (1 == 1 || 2 == event.uid) {
                                                var schdata = {
                                                    startdate : event.start,
                                                    enddate : event.end,
                                                    confid : event.confid,
                                                    sid : event.sid
                                                };
                                            }
                                            else {
                                                revertFunc();
                                            }
                                            
                                        },
                                        eventResizeStart : function(event, jsEvent, ui, view) {
                                            
                                            // alert('resizing');
                                            
                                        },
                                        eventResize : function(event, dayDelta, minuteDelta, revertFunc) {
                                            
                                            if (1 == 1 || 2 == event.uid) {
                                                var schdata = {
                                                    startdate : event.start,
                                                    enddate : event.end,
                                                    confid : event.confid,
                                                    sid : event.sid
                                                };
                                                
                                            }
                                            else {
                                                revertFunc();
                                            }
                                            
                                        }
                                    
                                    });
                    
                    // goto date function
                    $("#calendar .fc-header-right table td:eq(0)")
                            .before(
                                    '<td><div class="ui-state-default ui-corner-left ui-corner-right" style="border-right:0px;padding:1px 3px 2px;" ><input type="text" id="selecteddate" size="10" style="padding:0px;"></div></td><td><div class="ui-state-default ui-corner-left ui-corner-right"><a><span id="selectdate" class="ui-icon ui-icon-search">goto</span></a></div></td><td><span class="fc-header-space"></span></td>');
                    $("#selecteddate").datepicker({
                        dateFormat : 'yy-mm-dd',
                        beforeShow : function(input, instant) {
                            setTimeout(function() {
                                $('#ui-datepicker-div').css("z-index", 15);
                            }, 100);
                        }
                    });
                    
                    $("#selectdate").click(function() {
                        var selectdstr = $("#selecteddate").val();
                        var selectdate = $.fullCalendar.parseDate(selectdstr, "yyyy-mm-dd");
                        $('#calendar').fullCalendar('gotoDate', selectdate.getFullYear(), selectdate.getMonth(), selectdate.getDate());
                    });
                    
                    // conference function
                    $("#calendar .fc-header-left table td:eq(0)")
                            .before(
                                    '<td><div class="ui-state-default ui-corner-left ui-corner-right"  data-step="1" data-intro="选择会议室" data-position="left"><a id="selectmeeting"><span  class="ui-icon ui-icon-search" style="float: left;padding-left: 5px; padding-top:1px"></span><span id="roomname">meeting room</span></a></div></td><td><span class="fc-header-space"></span></td>');
                    $("#selectmeeting").click(function() { 
                        $("#dialog-meetingroom").dialog({
                            autoOpen : false,
                            height : 450,
                            width : 400,
                            modal : true,
                            buttons : {
                                确定 : function() {
                                    $("#meeting").val($("#meetingroom").val());
                                    $("#roomname").text($("#meetingroom").find("option:selected").text());
                                    $(this).dialog("close");
                                    var view = $('#calendar').fullCalendar("getView");
                                    var viewStart = $.fullCalendar.formatDate(view.start, "yyyy-MM-dd HH:mm:ss");
                                    var viewEnd = $.fullCalendar.formatDate(view.end, "yyyy-MM-dd HH:mm:ss");
                                    $("#calendar").fullCalendar('removeEvents');
                                    $.get("/meetings/books/" + $("#meetingroom").val(), {
                                        start : viewStart,
                                        end : viewEnd
                                    }, function(data) {
                                        var events = [];
                                        for ( var i = 0; i < data.length; i++) {
                                            var ev = data[i];
                                            events.push({
                                                title : ev.meetingTitle,
                                                start : new Date(ev.bookStartTime),
                                                end : new Date(ev.bookEndTime),
                                                id : ev.id,
                                                fullname : ev.meetingTitle,
                                                confname : ev.meetingName,
                                                confshortname : ev.meetingName,
                                                description : ev.meetingDescription,
                                                topic : ev.meetingTitle
                                            });
                                            for ( var i = 0; i < events.length; i++) {
                                                $("#calendar").fullCalendar('renderEvent', events[i], true);
                                            }
                                        }
                                        
                                    }); // 把从后台取出的数据进行封装以后在页面上以fullCalendar的方式进行显示
                                    
                                }
                            }
                        });
                        $("#dialog-meetingroom").dialog("open");
                        return false;
                    });
                    if($.cookie('intro')!="true"){
                    	$("#selecteddate").parent().attr("data-step","2").attr("data-intro","选择日期").attr("data-position","right");
                    	$(".fc-button-today").attr("data-step","3").attr("data-intro","今天").attr("data-position","left");
                    	$(".fc-button-month").attr("data-step","4").attr("data-intro","月视图").attr("data-position","right");
                    	$(".fc-button-agendaWeek").attr("data-step","5").attr("data-intro","周视图").attr("data-position","bottom");
                    	$(".fc-button-agendaDay").attr("data-step","6").attr("data-intro","日视图").attr("data-position","left");
                    	$(".fc-content").attr("data-step","7").attr("data-intro","默认显示所有预定").attr("data-position","top");
                    	introJs().start();
                		$.cookie('intro',"true",{expires:10000,path:"/"});
                	}
                    if(meetingId!=""){
                    	var meetingIdInt=parseInt(meetingId);
                    	var bookStartTimeFloat=parseFloat(bookStartTime);
                    	var bookEndTimeFloat=parseFloat(bookEndTime);
                    	$("#meeting").val(meetingIdInt);
                    	var selectdate= new Date(bookStartTimeFloat).pattern("yyyy-MM-dd");
                    	 $("#start").val(new Date(bookStartTimeFloat).pattern("HH:mm"));
                    	 $("#end").val(new Date(bookEndTimeFloat).pattern("HH:mm"));
                    	 $("#reservebox").dialog({
                             autoOpen : false,
                             height : 450,
                             width : 400,
                             title : '预约会议室于 ' + selectdate,
                             modal : true,
                             position : "center",
                             draggable : false,
                             beforeClose : function(event, ui) {
                                 $.validationEngine.closePrompt("#meeting");
                                 $.validationEngine.closePrompt("#start");
                                 $.validationEngine.closePrompt("#end");
                             },
                             buttons : {
                                 "关闭" : function() {
                                     $(this).dialog("close");
                                 },
                                 "预约" : function() {
                                     if ($("#reserveformID").validationEngine({
                                         returnIsValid : true
                                     })) {
                                         var startdatestr = $("#start").val();
                                         var enddatestr = $("#end").val();
                                         var title = $("#title").val(); // 标题
                                         var details = $("#details").val(); // 内容
                                         var confid = $("#meeting").val();
                                         var repweeks = $("#repweeks").val();
                                         if (repweeks == null) {
                                             repweeks = 0;
                                         }
                                         var startdate = $.fullCalendar.parseDate(selectdate + "T" + startdatestr);
                                         var enddate = $.fullCalendar.parseDate(selectdate + "T" + enddatestr);
                                         var event = new Object()
                                         event.fullname = title;
                                         event.confname = title;
                                         event.start = startdate;
                                         event.end = enddate;
                                         event.description = details;
                                         if (repweeks == 0) {
                                             var schdata = {
                                                 startdate : startdate.pattern("yyyy-MM-dd HH:mm:ss"),
                                                 enddate : enddate.pattern("yyyy-MM-dd HH:mm:ss"),
                                                 repweeks : repweeks,
                                                 meetingId : confid,
                                                 title : title,
                                                 details : details
                                             };
                                             $.get("/meetings/book", schdata, function(data) {
                                                 if (data == true) {
                                                     //$("#calendar").fullCalendar('renderEvent', event,true);
                                                     //$('#calendar').fullCalendar('updateEvent', event);
                                                     alert("预定会议成功！");
                                                     window.location.href=window.location.href;
                                                 }
                                                 else {
                                                     alert("预定会议失败！");
                                                 }
                                             });
                                         }
                                         else {
                                             var str = "";
                                             $("input[name='weeks']:checked").each(function() {
                                                 str += $(this).val() + ",";
                                             })
                                             var schdata = {
                                                 startdate : startdate.pattern("yyyy-MM-dd HH:mm:ss"),
                                                 enddate : enddate.pattern("yyyy-MM-dd HH:mm:ss"),
                                                 repweeks : repweeks,
                                                 meetingId : confid,
                                                 title : title,
                                                 details : details,
                                                 weeks : str
                                             };
                                             $.get("/meetings/book/periodic", schdata, function(data) {
                                                 var success=data[0];
                                                 var failed=data[1];
                                                 var html="";
                                                 for(var i=0;i<failed.length;i++){
                                                    var item=failed[i];
                                                    var temp='<div class="ui-state-error ui-corner-all"><p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span><strong>预约失败:</strong> '+item+'</p></div>';
                                                    html+=temp;
                                                 }
                                                 $("#dialog-book").html(html);
                                                 $("#dialog-book").dialog({
                                                     autoOpen : false,
                                                     height : 450,
                                                     width : 400,
                                                     title : '批量预定会议室失败 ',
                                                     modal : true,
                                                     position : "center",
                                                     draggable : false,
                                                     beforeClose : function(event, ui) {
                                                     },
                                                     buttons : {
                                                         "放弃预约" : function() {
                                                             $(this).dialog("close");
                                                         },
                                                         "继续预约" : function() {
                                                             $(this).dialog("close");
                                                             $.get("/meetings/book/lot", schdata, function(data) {
                                                                 if(data==0){
                                                                     alert("周期预约成功!");
                                                                     window.location.href=window.location.href;
                                                                 }
                                                                 else{
                                                                     alert("周期预约失败!");
                                                                 }
                                                             });
                                                         }
                                                     }
                                                 });
                                                 if(failed.length==0&&success.length>0){
                                                     $.get("/meetings/book/lot", schdata, function(result) {
                                                         if(result==0){
                                                             alert("周期预约成功!");
                                                             window.location.href=window.location.href;
                                                         }else if(result==-1){
                                                             alert("权限不够！");
                                                         }else if(result==-2){
                                                             alert("数据错误！");
                                                         }else{
                                                         	  alert("其他错误！");
                                                         }
                                                         
                                                     });
                                                 }
                                                 else{
                                                     if(success.length>0){
                                                     $("#dialog-book").dialog("open");
                                                     return false;
                                                     }
                                                     else{
                                                         alert("周期预约失败!");
                                                     }
                                                 }
                                                 
                                             });
                                         }
                                         $(this).dialog("close");
                                     }
                                 }
                             }
                         });
                         $("#reservebox").dialog("open");
                    }
                });

function compare2Date(startDate, endDate) {
    if (startDate.length > 0 && endDate.length > 0) {
        var arrStartDate = startDate.split("-");
        var arrEndDate = endDate.split("-");
        
        if ((arrStartDate[0] == arrEndDate[0] && arrStartDate[1] == arrEndDate[1] && arrStartDate[2] <= arrEndDate[2])
                || (arrStartDate[0] == arrEndDate[0] && arrStartDate[1] < arrEndDate[1]) || (arrStartDate[0] < arrEndDate[0])) {
            return 1;
        }
        else {
            return 0;
        }
    }
    else {
        return 0;
    }
}
function compare2time(startTime, endTime) {
    if (startTime.length > 0 && endTime.length > 0) {
        var arrStartTime = startTime.split(":");
        var arrEndTime = endTime.split(":");
        
        if ((arrStartTime[0] == arrEndTime[0] && arrStartTime[1] < arrEndTime[1]) || (arrStartTime[0] < arrEndTime[0])) {
            return 1;
        }
        else {
            return 0;
        }
    }
    else {
        return 0;
    }
}

function validate2time() {
    // alert("debug");
    
    var cresult = compare2time($("#start").val(), $("#end").val());
    if (cresult == 0) {
        return false;
    }
    else if (cresult == 1) {
        $.validationEngine.closePrompt("#start");
        return true;
    }
    
}
